/******************************************************************************
 * * mmi_modem_adaptor_sms.h - data structure for mmi-modem adpator, sms sub-module
 *
 * *(C) Copyright 2019 Asr International Ltd.
 * * All Rights Reserved
 * ******************************************************************************/
#ifndef MMI_MODEM_ADAPTOR_SMS_H
#define MMI_MODEM_ADAPTOR_SMS_H

#ifdef __cplusplus
extern "C" {
#endif

#include <string.h>
#include "mmi_modem_adaptor_main.h"
#include "mmi_modem_adaptor_nw.h"
#include "mmi_modem_adaptor_sim.h"

/******************************************************************************
 *
 *         Message structure of MMI -> Modem Adaptor
 *
 *******************************************************************************/
// msg stru: MMI_MODEMADP_SEND_SMS_REQ
// typedef struct {
// char                       *pSmsc;
// char                       *pSmsPdu;
// MMI_MODEM_WRITE_TO_SIM_FLG WriteToSimFlg;
// MMI_MODEM_SIM_ID           SimId;
// } MMI_Modem_Send_Sms_Req_t;

// msg stru: MMI_MODEMADP_DEL_SMS_REQ
// typedef struct {
// UINT16           DeleteMsgCnt;
// UINT32           *pMsgIndex;
// MMI_MODEM_SIM_ID SimId;
// } MMI_Modem_Delete_Sms_Req_t;

// msg stru: MMI_MODEMADP_OPEN_VOLTE_REQ
typedef struct {
    MMI_MODEM_SIM_ID SimId;
} MMI_Modemadp_Open_Volte_Req_t;

// msg stru: MMI_MODEMADP_READ_SMS_INFO_REQ
typedef struct {
    MMI_MODEM_SMS_OF_BOX SmsBox;
} MMI_Modemadp_Read_Sms_Info_t;

// msg stru: MMI_MODEMADP_READ_SMS_DETAIL_ON_SIM_REQ
// typedef struct {
// UINT32           MsgIndex;
// MMI_MODEM_SIM_ID SimId;
// } MMI_Modem_Read_Sms_Detail_On_Sim_Req_t;

// msg stru: MMI_MODEMADP_GET_SMSC_REQ
typedef struct {
    MMI_MODEM_SIM_ID SimId;
} MMI_Modemadp_Sms_Get_Smsc_Req_t;

// msg stru: MMI_MODEMADP_SET_SMSC_REQ
// typedef struct {
// char             *pSmsc;
// MMI_MODEM_SIM_ID SimId;
// } MMI_Modem_Set_Smsc_Req_t;

/******************************************************************************
 *
 *         Message structure of RIL -> Modem Adaptor
 *
 *******************************************************************************/
// msg stru: RIL_MODEMADP_MSG_RSP_SEND_SMS
// typedef struct _RIL_MSG_RESPONSE_SEND_SMS {
// RIL_SMS_RESPONSE *pSmsResponse;
// RIL_SIM_ID       eSimId;
// } RIL_MSG_RESPONSE_SEND_SMS;

// msg stru: RIL_MODEMADP_MSG_RSP_WRITE_SMS_TO_SIM
// typedef struct _RIL_MSG_RESPONSE_WRITE_SMS_TO_SIM {
// unsigned long ulWriteIndex;           // return the write index
// RIL_SIM_ID    eSimId;
// } RIL_MSG_RESPONSE_WRITE_SMS_TO_SIM;

// msg stru: RIL_MODEMADP_MSG_RSP_READ_SMS_INFO_FROM_SIM
// typedef struct _RIL_MSG_RESPONSE_READ_SMS_INFO_FROM_SIM {
// unsigned short                     usSmsResCnt;
// RIL_MSG_RESPONSE_READ_SMS_FROM_SIM *pSmsResponse;
// } RIL_MSG_RESPONSE_READ_SMS_INFO_FROM_SIM;

// msg stru: RIL_MODEMADP_MSG_RSP_READ_SINGLE_SMS_FROM_SIM
// typedef struct _RIL_MSG_RESPONSE_READ_SMS_FROM_SIM {
// RIL_MSG_READ_SMS_TYPE eReadSmsType;            // it should not use MSG_SMS_ALL to response
// unsigned short        usSmsPduLen;
// char                  *pcPdu;
// unsigned long         ulIndex;
// RIL_SIM_ID            eSimId;
// } RIL_MSG_RESPONSE_READ_SMS_FROM_SIM;

// msg stru: RIL_MODEMADP_MSG_RSP_GET_SMSC_ADDR
// typedef struct _RIL_MSG_RESPONSE_GET_SMSC_ADDRESS {
// unsigned short ucSmscAddrLen;
// char           *pcSmsc;
// RIL_SIM_ID     eSimId;
// } RIL_MSG_RESPONSE_GET_SMSC_ADDRESS;

// msg stru: RIL_MODEMADP_MSG_RSP_NEW_SMS_ON_SIM
// typedef struct _RIL_MSG_RESPONSE_NEW_SMS_ON_SIM {
// int        iIndex;
// RIL_SIM_ID eSimId;
// } RIL_MSG_RESPONSE_NEW_SMS_ON_SIM;

typedef enum {
    MODEM_SMS_READING_SINGLE_SMS = 0,
    MODEM_SMS_READING_MULTY_SMS_UNREAD,
    MODEM_SMS_READING_MULTY_SMS_READ,
    MODEM_SMS_READING_MULTY_SMS_SENT,
    MODEM_SMS_READING_MULTY_SMS_ALL,
    MODEM_SMS_SENDING,
    MODEM_SMS_NEW_SMS_READING_SINGLE_SMS,
    MODEM_SMS_WRITING,
    MODEM_SMS_IDLE,
} MODEM_SMS_STATUS;

enum
{
    MODEM_SMS_IEID_8BIT_SN = 0,                        // Concatenated short messages, 8-bit reference number
    MODEM_SMS_IEID_16BIT_SN = 0x08,                    // Concatenated short message, 16-bit reference number
    MODEM_SMS_IEID_INVALID = 0xFF
};

typedef struct {
    uint8_t  Data[184 * 2];
    uint16_t DataLen;
    void     *Next;
} Modem_SMS_Encode_Pdu_t;

typedef struct {
    MMI_MODEM_SIM_ID SimId;
    char * data;                                       //sms data
    char * number;                                     //the number of send to
    uint8_t send_flg;                                  //for 0:send the China Mobile's message"KTVOLTE",1:send the China Mobile's message"KTGQTH"
} MMI_ModemAdp_Check_China_Operator_t;

typedef struct {
    MODEM_SMS_STATUS          SmsStatus[2];
    BOOL                      DeliverStatusReport[2];  // true means send report to UI

    BOOL                      WriteToSim;              // from send SMS interface
    INT8                      *pSendSms_Smsc[2];
    INT8                      *pSendSms_Pdu;
    MMI_MODEM_SMS_RESULT_TYPE SendSms_Result;
    watch_app_adp_sms_code_type_t decode_type;
    app_adaptor_new_sms_info_ind NewSmsInfoIndFunc;
    app_adaptor_new_sms_info_ind New8bitSmsInfoIndFunc;
    app_adaptor_sms_send_result_ind SmsSendResultIndFunc;
    INT8                      *pSegPdu[16];
    UINT8                     SegPduLen[16];
    UINT8                     SegPduTotalCnt;
    UINT8                     SegPduRcvCnt;
    UINT16                    SegPduTotalLen;
    UINT16                    SegPduId;
    UINT8                     IEId;                   // The Information Element Identifier,refer to TS23.040
    BOOL                      MsmsValid;
    uint8_t                   RefNum;                 /* 0 ~ 255, reference number for the header of
                                                       * TP-UDH of the concatenated short messages */
    uint8_t                   MoSmsSegNum;
    UINT8                     VolteOpenSmsFlg;        //if the operator is "China Telecom" or "China Unicom",after sent the first SMS(the first SMS of "China Telecom" is "ktVOLTE",
                                                      //the first SMS of "China Unicom" is "DGVOLTE"),VolteOpenSmsFlg will set to 1.And then recieved the SMS with "Y"
                                                      //from operator service center,VolteOpenSmsFlg will set to 0.if the operator is "China Mobile",VolteOpenSmsFlg will never
                                                      //to be set.
    UINT8                     ChinaMobileFlg;         //after send first sms"KTVOLTE" set to 1,after send second sms"KTGQTH" set to 0
} Modem_SMS_Mng_t;

extern Modem_SMS_Mng_t g_ModemSmsMng;

extern MMI_MODEM_READ_SMS_TYPE MMI_ModemAdp_Get_UI_Sms_Type(RIL_MSG_READ_SMS_TYPE RilSmsType);
extern uint32_t EncodeSmsc(char * smscNum, uint32_t smscNumLen, uint8_t * pSmscPdu);
extern uint16_t DecodeSmsPdu(char * pSrcInfoIn, char * number, char * time, char * data, uint8_t decode_type, uint8_t * udhi, uint8_t * dcs);
extern char* DecodeSegPdu(uint16_t * data_len, uint8_t dcs, uint8_t decode_type);
extern VOID MMI_ModemAdp_Check_China_Operator(MMI_ModemAdp_Check_China_Operator_t *Operator);

#ifdef __cplusplus
} /* extern "C" */
#endif

#endif /*SETTING_CALL_H*/
